package com.net.xpay.partner.controller.partner;

import com.net.common.model.ResultData;
import com.net.xpay.common.domain.partner.Partner;
import com.net.xpay.common.domain.stat.PartnerRealTimeStat;
import com.net.xpay.common.manager.UserManager;
import com.net.xpay.common.manager.stat.PartnerRealTimeStatManager;
import com.net.xpay.partner.secutiry.RequestUser;
import com.net.xpay.partner.vo.PartnerRealTimeStatVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.math.BigDecimal;

/**
 * @author  on 20/03/2018.
 * 查询合伙人统计数据
 */
@RestController
@RequestMapping("/partner/partner-real-time-stat")
@Api(tags = "合伙人/合伙人的商户实时统计数据", description = "合伙人 实时统计数据 zc")
public class PartnerRealTimeStatController {

    @Autowired
    private PartnerRealTimeStatManager partnerRealTimeStatManager;

    @Autowired
    private UserManager userManager;

    @ApiOperation("聚合实时搜索合伙人的商户数据")
    @PostMapping("/agg-select")
    @ResponseBody
    public ResultData<PartnerRealTimeStatVo> getPartnerRealTimeStat(@ApiIgnore @RequestUser Partner partner) {
        PartnerRealTimeStat partnerRealTimeStat = partnerRealTimeStatManager.getByPartnerId(partner.getId());
        PartnerRealTimeStatVo vo = new PartnerRealTimeStatVo();

        if (partnerRealTimeStat == null) {
            vo.setServiceChargeFee(new BigDecimal("0"));
            vo.setTotalSuccessCount(0L);
            vo.setTotalServicePrice(new BigDecimal("0"));
            vo.setRegisterCount(0L);

            return new ResultData<>(vo);
        }

        vo.setServiceChargeFee(partnerRealTimeStat.getServiceChargeFee());
        vo.setTotalSuccessCount(partnerRealTimeStat.getTotalSuccessCount());
        vo.setTotalServicePrice(partnerRealTimeStat.getTotalServicePrice());
        vo.setRegisterCount(partnerRealTimeStat.getRegisterCount());
        vo.setUpdateTime(partnerRealTimeStat.getUpdateTime());
        return new ResultData<>(vo);
    }

}
